/**
 * 2018年12月16日下午10:39:34
 * @author 谢进财
 */
package com.baihang.project.ds.bean;

import javax.servlet.ServletContext;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ServletContextAware;

import com.baihang.framework.kit.PropKit;
import com.baihang.framework.kit.database.RedisKit;
import com.baihang.project.ds.dao.SystemConfigDao;

/**
 * 项目初始化方法
 * 启动执行
 */
@Component
public class StartupListener
		implements ApplicationContextAware, ServletContextAware, InitializingBean, ApplicationListener<ContextRefreshedEvent> {
	@Autowired
	private SystemConfigDao dao;
	/* (non-Javadoc)
	 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
	 */
	@Override
	public void afterPropertiesSet() throws Exception {
		// TODO Auto-generated method stub
		//System.err.println(1);
	}

	/* (non-Javadoc)
	 * @see org.springframework.web.context.ServletContextAware#setServletContext(javax.servlet.ServletContext)
	 */
	@Override
	public void setServletContext(ServletContext arg0) {
		// TODO Auto-generated method stub
		//System.err.println(2);
	}

	/* (non-Javadoc)
	 * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
	 */
	@Override
	public void setApplicationContext(ApplicationContext arg0) throws BeansException {
		// TODO Auto-generated method stub
		//System.err.println(3);
		PropKit.use("application.properties");//读取配置文件
		/*RedisKit.HOST = PropKit.get("redisHOST");
		RedisKit.PORT = Integer.valueOf(PropKit.get("redisPORT"));
		RedisKit.PWD = PropKit.get("redisPWD");*/
		/*List<Record> list = dao.queryForRecordList("select * from sys_config");
		Jedis jedis = RedisKit.getJedis();
		Map<String,String> configMap = new HashMap<String,String>();
		for(Record rec:list) {
			//SystemConfig.configMap.put(rec.getStr("Name"), rec.getStr("Value"));
			configMap.put(rec.getStr("Name"), rec.getStr("Value"));
		}
		jedis.hmset("systemConfig", configMap);*/
	}

	/* (non-Javadoc)
	 * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
	 */
	@Override
	public void onApplicationEvent(ContextRefreshedEvent arg0) {
		// TODO Auto-generated method stub
		//System.err.println(4);
	}

}
